package com.loongxun.xxapp.ui.phone;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.loongxun.xxapp.R;

/**
 * Created by Administrator on 2017/10/27.
 */
public class PhoneBindingActivity extends Activity implements View.OnClickListener{

    private TextView tv_title;

    private SharedPreferences share;
    private SharedPreferences.Editor editor;
    private String user_id;

    private TextView tv_brn_Phone,tv_phone_binding;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_phone_binding);

        findViewById(R.id.iv_back).setOnClickListener(this);
        tv_title = (TextView) findViewById(R.id.tv_title);
        tv_title.setText("呼叫转移");

        share = getSharedPreferences("userInfo", 0);
        editor = share.edit();//获取编辑器
        user_id = share.getString("user_id", "");

        tv_brn_Phone = (TextView) findViewById(R.id.tv_brn_Phone);

        tv_phone_binding = (TextView) findViewById(R.id.tv_phone_binding);
        tv_phone_binding.setOnClickListener(this);

        //有手机号
        if (!"".equals(user_id)) {
            findViewById(R.id.iv_phone_binding).setVisibility(View.VISIBLE);
            tv_brn_Phone.setText("已绑定手机号：18725631542");
            tv_phone_binding.setText("更换手机号");
        }else {
            findViewById(R.id.iv_phone_binding).setVisibility(View.INVISIBLE);
            tv_brn_Phone.setText("未绑定手机号");
            tv_phone_binding.setText("绑定手机号");
        }

    }

    @Override
    public void onClick(View view) {
        Intent intent;
        switch (view.getId()){
            case R.id.iv_back:
                finish();
                break;
            case R.id.tv_phone_binding:
                intent = new Intent(this,PhoneChangeActivity.class);
                startActivityForResult(intent,2);
                break;
            default:
                break;
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == 2) {
            if (data != null){
//                CloseKeyBoard();
                Intent intent = new Intent();
                intent.putExtra("login", true);
                setResult(Activity.RESULT_OK, intent);
                finish();
            }
        }
    }
}
